import java.util.Iterator;
import java.util.LinkedList;

/**
 * @Author: biubiu0002
 * @Date: 2022/8/9 18:08
 **/
public class Q2 {

    public int getNumber(int[] a) {
        boolean[] isNotPrime = isNotPrimes(a.length + 1);
//        System.out.println(Arrays.toString(isPrime));
        LinkedList<Integer> list = new LinkedList<Integer>();
        for (int num : a) {
            list.add(num);
        }
        while (list.size() > 1) {
            int index = 1;
            Iterator<Integer> iterator = list.iterator();
            while (iterator.hasNext()) {
                int num = iterator.next();
                if (isNotPrime[index]) {
//                    System.out.println(index);
                    iterator.remove();
                }
                index++;
            }
//            System.out.println(list);
        }
        return list.get(0);
    }

    private boolean[] isNotPrimes(int n) {
        boolean[] isPrime = new boolean[n];
        isPrime[1] = true;
        for (int i = 2; i < n; i++) {
            for (int j = 2; i * j < n; j ++) {
                isPrime[i * j] = true;
            }
        }
        return isPrime;
    }


    public static void main(String[] args) {
        System.out.println(new Q2().getNumber(new int[]{3,1,1,4,5,6}));
        //6?
//        System.out.println(new Q2().getNumber(new int[]{0,1,2,3,4,5}));
    }
}
